package com.javafamily.familydemo.model;

import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

import javax.validation.constraints.Min;

@Data
// 使校验注解生效（@min）
@Validated
@Component
// @ConfigurationProperties注解不能使用驼峰写法
@ConfigurationProperties(prefix = "petstore")
// @PropertySource(value = "classpath:family.yml") 默认支持.Properties文件，如果不是，则需要在MixPropertySourceFactory对方法进行充血
public class PetStore {
    // 在应用启动时，自动将petStore.petStoreName属性的值绑定到私有变量petStoreName上面，实现赋值效果。
    // @Value("${petStore.petStoreName}")
    private String petStoreName;
    private Manager manager;
    private Employee employee;
    private Pet pet;
}

@Data
class Manager {
    private String title;
    private String name;
}

@Data
class Employee {
    private String[] name;
}

@Data
class Pet {
    private String name;
    private String variety;
    private Parents[] parents;
}

@Data
class Parents {
    private String variety;
   // 父母最小的年龄是2岁，如果在.yml中配置的父母年龄小于2，则说明不符合要求
   // @Min(2)
    private Integer age;
}